/**   
 * Copyright © 2016 北京之洲科技有限责任公司. All rights reserved.
 * 
 * @Title: BBSDAO.java 
 * @Prject: carfactory
 * @Package: com.zizo.autohome.bbs.dao 
 * @Description: 
 * @author: Alexis  
 * @email heyan0227@outlook.com
 * @date: 2016年7月26日 上午11:51:16 
 * @version: V1.0   
 */
package com.zizo.autohome.choice.dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.zizo.autohome.choice.bean.AutoHomeChoice;
import com.zizo.core.DAO;
import com.zizo.core.T;
import com.zizo.util.Util;

/**
 * @ClassName: BBSDAO
 * @Description:
 * @author: Alexis
 * @date: 2016年7月26日 上午11:51:16
 */
public class ChoiceDAOOfAutoHome extends DAO {

	/**
	 * @Title:BBSDAO
	 * @Description:
	 * @param currConn
	 */
	public ChoiceDAOOfAutoHome(Connection currConn) {
		super(currConn);
		// TODO Auto-generated constructor stub
	}
////sql语句未修改
	public List<String> getFinID() {
		Statement st = null;
		ResultSet rs = null;
		List<String> list = new ArrayList<>();
		String sql = "SELECT id FROM qczj_choice_fin";
		try {
			st = currConn.createStatement();
			rs = st.executeQuery(sql);
			while (rs.next()) {
				list.add(rs.getInt("id") + "");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: getIDs
	 * 
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#getIDs()
	 * sql语句未修改
	 */
	@Override
	public List<String> getIDs() {
		Statement st = null;
		ResultSet rs = null;
		List<String> ids = new ArrayList<>();
		String sql = "SELECT id FROM qczj_choice_id";
		try {
			st = currConn.createStatement();
			rs = st.executeQuery(sql);
			while (rs.next()) {
				ids.add(rs.getInt("id") + "");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return ids;
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: insertData
	 * 
	 * @Description:
	 * 
	 * @param t
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#insertData(com.zizo.core.T)
	 */
	public int insertData(T t, String tableName) {
		PreparedStatement ps = null;
		String sql = "REPLACE INTO " + tableName
				+ "(bsb_bbsid,bbs_title,bbs_qa,bbs_jing,bbs_content,bbs_ptime,bbs_djs,bbs_hfs,bbs_uid,bbs_yhmc,bbs_jhs,bbs_yhfts,bbs_yhhts,bbs_zcsj,bbs_sf,bbs_cs,bbs_rz,bbs_khd,bbs_cid,bbs_uptime,bbs_jing_type) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		AutoHomeChoice bbs = (AutoHomeChoice) t;
		try {
			ps = currConn.prepareStatement(sql);
			ps.setInt(1, bbs.getBbsID());
			ps.setString(2, bbs.getTopic());
			ps.setInt(3, bbs.getQuestion());
			ps.setInt(4, bbs.getEssence());
			ps.setString(5, bbs.getContent());
			ps.setTimestamp(6, (Timestamp) Util.getTimeHMS(bbs.getPostTime()));
			ps.setInt(7, bbs.getHitCount());
			ps.setInt(8, bbs.getReplyCount());
			ps.setInt(9, bbs.getUserID());
			ps.setString(10, bbs.getUserName());
			ps.setInt(11, bbs.getEssenceCount());
			ps.setInt(12, bbs.getPostCount());
			ps.setInt(13, bbs.getRepCount());
			ps.setDate(14, (Date) Util.getDate(bbs.getRegisterDate()));
			ps.setString(15, bbs.getProvince());
			ps.setString(16, bbs.getCity());
			ps.setInt(17, bbs.getCertificationCars());
			ps.setString(18, bbs.getClientFrom());
			ps.setString(19, bbs.getBrandID());
			ps.setTimestamp(20, (Timestamp) Util.getTimeHMS(bbs.getUpdateTime()));
			ps.setInt(21, bbs.getType());
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return 0;

	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: updateTime
	 * 
	 * @Description:
	 * 
	 * @param type
	 * 
	 * @param id
	 * 
	 * @see com.zizo.core.DAOInterface#updateTime(java.lang.String,
	 * java.lang.String)
	 */
	@Override
	public void updateTime(String type, String id) {

	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: getTables
	 * 
	 * @Description:
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#getTables()
	 */
	@Override
	public List<String> getTables() {
		return null;
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: insertError
	 * 
	 * @Description:
	 * 
	 * @param t
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#insertError(com.zizo.core.T)
	 */
	@Override
	public int insertError(T t) {
		// TODO Auto-generated method stub
		return 0;
	}

	/**
	 * @Title: createTable
	 * @Description: 创建新表，BBS每一个品牌放在一个表中
	 * @param tableName
	 * @return: void
	 * @author: Alexis
	 *  sql语句未修改
	 */
	public void createTable(String tableName) {
		Statement st = null;
		String sql = "CREATE TABLE IF NOT EXISTS " + tableName + " LIKE qczj_bbs";
		try {
			st = currConn.createStatement();
			st.executeUpdate(sql);
		} catch (SQLException e) {
		}
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: insertData
	 * 
	 * @Description:
	 * 
	 * @param t
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#insertData(com.zizo.core.T)
	 */
	@Override
	public int insertData(T t) {
		// TODO Auto-generated method stub
		return 0;
	}

}
